﻿using MongoDB.Bson;
using System;
using System.ComponentModel.DataAnnotations;

namespace ldhWebApiWF.models
{
    public class Book
    {
        public ObjectId Id { get; set; }
        [Required(ErrorMessage = "书名不能空")]
        [Display(Name = "名书")]
        [StringLength(128, MinimumLength = 1, ErrorMessage = "字长要在1至128之间")]
        public string Title { get; set; }
        [Required(ErrorMessage = "日期不能空")]
        [Display(Name = "发布日期")]
        [Range(typeof(DateTime), "1966-01-01", "2020-01-01")]
        [DataType(DataType.DateTime, ErrorMessage = "不是有效的日期类型")]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-ddTHH:mm:ss}", ApplyFormatInEditMode = true)]
        public DateTime ReleaseDate { get; set; }
        [Display(Name = "出版社")]
        [Required(ErrorMessage = "出版社不能空")]
        //[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$", ErrorMessage = "必需大写字母开头及只限英文")]
        public string Genre { get; set; }
        [Required(ErrorMessage = "售价不能空")]
        [Display(Name = "售价")]
        [Range(1, 999999999)]
        [DataType(DataType.Currency)]
        public double? Price { get; set; }
        [Display(Name = "评价")]
        public em_staute staute { get; set; }

        //[Required(ErrorMessage = "作者不能空")]
        public virtual Author author { get; set; }
    }

    public class Author
    {
        [Display(Name = "作者")]
        [Required]
        public string Name { get; set; }
    }

    public enum em_staute
    {
        普通 = 0, 好 = 1, 非凡 = 2
    }

}
